package com.lxh.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lxh.entity.ChinaCity;
import com.lxh.entity.dto.ChinaCityDto;
import com.lxh.entity.vo.ChinaCityVo;
import com.lxh.service.ChinaCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 中国省市区 前端控制器
 * </p>
 *
 * @author lxh
 * @since 2022-03-01
 */
@Api("中国省市区 前端控制器")
@RequiredArgsConstructor
@RestController
@RequestMapping("/china-city")
public class ChinaCityController {

    private final ChinaCityService chinaCityService;

    /**
     * 不分页获取
     * @param dto /
     * @return java.util.List<com.lxh.entity.ChinaCity> /
     * @author lxh
     * @date 2022/3/2 15:44
     */
    @ApiOperation(value = "不分页获取省市县列表")
    @GetMapping("/getAll")
    public List<ChinaCity> getAll(ChinaCityDto dto) {
        return chinaCityService.getChinaList(dto);
    }

    /**
     * 树结构（通过工具类获取）
     * @param dto /
     * @return java.util.List<com.lxh.entity.vo.ChinaCityVo> /
     * @author lxh
     * @date 2022/3/2 15:44
     */
    @ApiOperation(value = "树结构（通过工具类获取）")
    @GetMapping("/getTree")
    public List<ChinaCityVo> getTree(ChinaCityDto dto) {
        return chinaCityService.getChinaTree(dto);
    }

    /**
     * 分页获取
     * @param dto /
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.lxh.entity.ChinaCity> /
     * @author lxh
     * @date 2022/3/2 15:44
     */
    @ApiOperation(value = "分页获取省市县列表")
    @GetMapping("/getPage")
    public IPage<ChinaCity> getPage(ChinaCityDto dto) {
        return chinaCityService.getPage(dto);
    }

    /**
     * 树结构（原生）
     * @return java.util.List<com.lxh.entity.ChinaCity> /
     * @author lxh
     * @date 2022/4/14 11:58
     */
    @ApiOperation(value = "树结构（原生）")
    @GetMapping("/getTree1")
    public List<ChinaCity> getTree1() {
        return chinaCityService.getChinaTree1();
    }
}
